﻿Imports QLTHUVIEN.DTO
Imports QLTHUVIEN.BUS
Public Class frmLoaiDocGia
    Private Sub layDanhSach()
        Dim LoaiDocGiaBus As LoaiDocGiaBUS = New LoaiDocGiaBUS()
        Dim data As DataTable = LoaiDocGiaBus.LayDanhSach()
        dtgDanhSachLoaiDocGia.DataSource = data
    End Sub
    Private Sub frmLoaiDocGia_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        layDanhSach()
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        If txtTenLoaiDocGia.Text = "" Then
            Return
        End If

        Dim LoaiDocGiaDto As New LoaiDocGiaDTO()
        LoaiDocGiaDto.TenLoaiDocGia = txtTenLoaiDocGia.Text

        Dim ldgBus As New LoaiDocGiaBUS()
        ldgBus.ThemLoaiDocGia(LoaiDocGiaDto)

        layDanhSach()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        If txtTenLoaiDocGia.Text = "" Or txtMaLoaiDocGia.Text = "" Then
            Return
        End If

        Dim LoaiDocGiaDto As New LoaiDocGiaDTO()
        LoaiDocGiaDto.MaLoaiDocGia = txtMaLoaiDocGia.Text
        LoaiDocGiaDto.TenLoaiDocGia = txtTenLoaiDocGia.Text

        Dim ldgBus As New LoaiDocGiaBUS()
        ldgBus.SuaLoaiDocGia(LoaiDocGiaDto)

        layDanhSach()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        If txtTenLoaiDocGia.Text = "" Or txtMaLoaiDocGia.Text = "" Then
            Return
        End If

        Dim LoaiDocGiaDto As New LoaiDocGiaDTO()
        LoaiDocGiaDto.MaLoaiDocGia = txtMaLoaiDocGia.Text
        LoaiDocGiaDto.TenLoaiDocGia = txtTenLoaiDocGia.Text
        LoaiDocGiaDto.IsDelete = True

        Dim ldgBus As New LoaiDocGiaBUS()
        ldgBus.XoaLoaiDocGia(LoaiDocGiaDto)

        layDanhSach()
    End Sub

    Private Sub dtgDanhSachLoaiDocGia_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgDanhSachLoaiDocGia.CellClick
        txtMaLoaiDocGia.Text = dtgDanhSachLoaiDocGia.CurrentRow.Cells(0).Value.ToString()
        txtTenLoaiDocGia.Text = dtgDanhSachLoaiDocGia.CurrentRow.Cells(1).Value.ToString()
    End Sub
End Class